import requests
import json
from add_course import get_user_course
from add_course import login

token = login()
data = get_user_course(token=token, userNo='4079769899')  # 获取用户的所有课程以及studentCourseId
studentCourseId = data[0]
courseIds = data[1]
print('一共%s个课程' % len(courseIds))
num = 1
for courseId in courseIds:
    url = "https://crm.hongsong.info/gateway/api/fjkt-crm-course-ui-interfaces/student/course/relation/update/valid/time"

    payload = json.dumps({
        "courseValidStartTime": "2021-10-01 00:00:00",
        "courseValidEndTime": "2025-10-01 23:59:59",
        "studentCourseId": int(studentCourseId),
        "courseId": int(courseId)
    })
    headers = {
        'authority': 'crm.hongsong.info',
        'istio-v': 'feature-clip-0829',
        'loginsource': 'crm',
        'token': 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJmYW5jaGFvQGhvbmdzb25nLmNsdWIiLCJjcmVhdGVkIjoxNjk0NDEyOTYwMDA5LCJleHAiOjE2OTcwMzk1MjB9.yNEsjQAqQ6pPYFaWgeijf5HLFG_aoEqzB3wr1LokoRNdFgn2YleOfd2HA2SyYmN6anA0A2m52xsDgswn7lGlmQ',
        'userid': 'null',
        'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
        'content-type': 'application/json'
    }

    response = requests.request("POST", url, headers=headers, data=payload)

    print(response.text)
    print('第%s条数据执行完毕' % num)
    num += 1
